--
-- Author: mm
-- Date: 2018-03-19 14:55:37
--
-- NewguildRender 对应 Node_guild_list.csb
-- 工会列表render

local NewguildIconRender = import(".NewguildIconRender")

local ClassRef = app.mvc.createListViewCell(...)

local JOIN_CD = 10 -- 加入具体目标CD时间

function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.NewGuildNode))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

function ClassRef:init(data)
    self.super.init(self, data)
    self:setContentSize(self._ui.Panel:getContentSize())

    -- self._ui.Panel:setTouchEnabled( true )
    -- display.uiAddClick( self._ui.Panel, function()
    --     executeFunc(self._onClick, "selected_Guild", self._data) -- 选中具体公会
    -- end )

    self._guildIcon = NewguildIconRender.create( self._ui.icon ) -- 公会图标
    self._guildIcon:onBtnClick( function()
        self:dispatchCellEvent("selected_Guild", self._data)
    end )
    self._ui.Button_join:addClickEventListener(function()
        self:dispatchCellEvent("applyJoin_Guild", self._data)
    end)

    self._ui.Button_detail:addClickEventListener(function()
        app:sendMsg( "NewRankController", "showGuildDetailView", self._data)
    end)

    self:refresh()
end

-- data = NewguildInfo 结构
function ClassRef:refresh()

    -- dump( self._data, " ------------------->>>> NewguildRender:refresh" )

    if self._data then
        self:setVisible( true )

        local data = self._data
        local str = table.concat( { data:getGuildName(), "  ", L("text_10000098"), data:getGuildLv() } )
        self._ui.Text_name:setString( str ) -- 公会名字
        self._ui.combat_num:setString( data:getGuildMemberNum() ) -- 公会人数
        self._ui.Text_guild:setString( data:getGuildLeaderName() ) -- 会长名字
        self._guildIcon:setData( data:getGuildIcon() ) -- 公会头像

        self._ui.Button_join:setVisible( not data:hadApplied() )
        self._ui.Button_over:setVisible( data:hadApplied() )
    else
        self:setVisible( false )
    end
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

return ClassRef
